package com.automapper.bytecode;

import java.util.HashMap;

import com.automapper.bytecode.javassist.JavassistInsertSqlWriterCreator;
import com.automapper.utils.ObjectFacade;

public class ByteCodeFactory {
	
	private static HashMap<String, SqlWriter> sqlWriters = new HashMap<>();
	
	public static SqlWriter createSqlWriter(ObjectFacade objectFacade, String key,  String sqlPlaceholderAlias) throws Exception {
		Class<?> clazz = objectFacade.getOriginalObject().getClass();
		String mapKey = clazz + key; 
		if (!sqlWriters.containsKey(mapKey)) {
			JavassistInsertSqlWriterCreator creator = new JavassistInsertSqlWriterCreator();
			SqlWriter sqlWriter = creator.create(objectFacade, sqlPlaceholderAlias);
			sqlWriters.put(mapKey, sqlWriter);
		}
		return sqlWriters.get(mapKey);
	}
}
